# T2401020100224 刘勋
import pandas as pd
import matplotlib.pyplot as plt

file_path = r'全国人口年度数据.xlsx'
data = pd.read_excel(file_path)
years = data['年份']
urban_population = data['城镇人口（万人）']
rural_population = data['乡村人口（万人）']
plt.figure(figsize=(14, 8))
plt.plot(years, rural_population, label='乡村人口', color='r', marker='^')
plt.plot(years, urban_population, label='城镇人口', color='g', marker='o')
plt.title('2003年至2023年全国城镇与乡村人口变化折线图', color='#008B8B', fontsize=16)
plt.xlabel('年份', color='#008B8B', fontsize=14)
plt.ylabel('人口（万人）', color='#008B8B', fontsize=14)
plt.grid(axis='both')
for i, year in enumerate(years):
    pop = urban_population[i]
    plt.text(year, pop, pop, fontsize=10, ha='right', va='bottom')
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.show()
